<!DOCTYPE html>
<html lang="zh-cmn-Hans">

	<head>
		<meta http-equiv="Expires" content="0" />
		<meta http-equiv="Pragma" content="no-cache" />
		<meta http-equiv="Cache-control" content="no-cache" />
		<meta http-equiv="Cache" content="no-cache" />
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
		<title>生产首/自检运转记录</title>
		<link rel="stylesheet" href="../layui/css/layui.css">
		<link rel="stylesheet" href="../jexcel-master/dist/css/jquery.jexcel.css" />
	</head>

	<body>
		<fieldset class="layui-elem-field site-demo-button">
			<legend><big><b>生产首/自检运转记录</b></big></legend>
			<div class="layui-fluid layui-form layui-form-pane">
				<div class="layui-row layui-form-item">
					<label class="layui-form-label">扫描二维码:</label>
					<div class="layui-input-block">
						<input class="layui-input" placeholder="请扫入特定的二维码" id="qr" type="text" />
					</div>
				</div>
			</div>
		</fieldset>

		<fieldset class="layui-elem-field site-demo-button">
			<legend><big><b>这里是当前扫描的信息组合</b></big></legend>
			<div id="DQ" class="layui-fluid layui-form layui-form-pane">
				<div class="layui-col-sm4">
					<label class="layui-form-label">员工工号:</label>
					<div class="layui-input-block">
						<input class="layui-input" readonly=true placeholder="这里是员工工号" id="YGGH" type="text" />
					</div>
				</div>

				<div class="layui-col-sm4">
					<label class="layui-form-label">员工姓名:</label>
					<div class="layui-input-block">
						<input class="layui-input" readonly=true placeholder="这里是员工姓名" id="YGXM" type="text" />
					</div>
				</div>

				<div class="layui-row">
					<div class="layui-col-sm4">
						<label class="layui-form-label">当前机台:</label>
						<div class="layui-input-block">
							<input class="layui-input" readonly=true placeholder="这里是当前机台" id="DQJT" type="text" />
						</div>
					</div>

					<div class="layui-col-sm4">
						<label class="layui-form-label">工单号:</label>
						<div class="layui-input-block">
							<input class="layui-input" readonly=true placeholder="这里是工单号" id="GDH" type="text" />
						</div>
					</div>
				</div>
			</div>
		</fieldset>

		<fieldset class="layui-elem-field site-demo-button">
			<legend><big><b>异常报修项</b></big></legend>
			<div class="layui-btn-container" class="layui-row"  id='abnormal'></div>
		</fieldset>
		
		<div class="layui-tab layui-tab-card" lay-filter="demo">
			<ul class="layui-tab-title">
				<li class="layui-this">产能/异常/首检/自检</li>
				<li lay-id='zjid' onclick="zijian(this)">自检作业区</li>
				<li>通讯区</li>
			</ul>
			<div class="layui-tab-content">
				<div id="BG" class="layui-tab-item layui-show">
					<div class="layui-fluid layui-form layui-form-pane">
						<div id="YC" class="layui-row"></div>
					</div>
				</div>
				<div id="ZJ" class="layui-tab-item">
					<div id="DQ" class="layui-fluid layui-form layui-form-pane">

						<!-- 这里是JExcel的表格位置 -->
						<div id="mytable"></div>
						<div class="layui-row">
							<label class="layui-form-label">判定结果:</label>
							<input type="radio" name="jyjg" value="OK" title="OK判定通过" lay-filter="jyjg">
							<input type="radio" name="jyjg" value="NG" title="NG检验不通过" lay-filter="jyjg">
						</div>
						<div class="layui-row">
							<div class="layui-form-item layui-form-text layui-col-sm12">
								<label class="layui-form-label ">整单备注:</label>
								<div class="layui-input-block">
									<textarea placeholder="请填写备注" class="layui-textarea" id="BZSTR"></textarea>
								</div>
							</div>
						</div>
						<div class="layui-row layui-btn-container">
							<div class="layui-col-sm4">
								<button class="layui-btn  layui-btn-normal" id="keep">保存</button>
							</div>
						</div>
						<fieldset class="layui-elem-field site-demo-button layui-btn-container">
							<legend><big><b>自检项目列表</b></big></legend>
							<div class="layui-fluid layui-form layui-form-pane">
								<div id="YCQ" class="layui-row layui-btn-container"></div>
							</div>
						</fieldset>
					</div>
				</div>

				<div id="TX" class="layui-tab-item">
					当前用户uid：<b id="uid"></b><br/> 在线用户: <b id="online_box"></b>
					<div class="layui-row layui-fluid layui-form layui-form-pane">
						<div class="layui-form-item layui-form-text layui-col-sm12">
							<label class="layui-form-label ">消息:</label>
							<div class="layui-input-block">
								<textarea id="information" class="layui-textarea"> </textarea>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>

		<!-- 加载jQuery文件 -->
		<script src="../js/jquery.min.js"></script>
		<!-- 加载类ui文件 -->
		<script src="../layui/layui.js"></script>
		<!-- 加载socket.io文件 -->
		<script src="../js/socket.io.js"></script>
		<!-- 加载socket的脚本 -->
		<script src="./notify.js"></script>
		<!-- 加载JExcel文件 -->
		<script src="../jexcel-master/dist/js/jquery.jexcel.js"></script>
		<!-- 写脚本 -->
		<script>
			//全局变量
			var prf = true; //控制是否弹出pr
			var zjler; //暴露全局的支架弹窗
			//var zjf = true; //控制是否弹出zj
			var jpfx = 0; //晶片反向
			var zjfx = 0; //支架反向
			var GD = "";
			var Hhtml = ""; //画窗口的画面,把程序写到Layer里面
			var Dhtml = ""; //画窗口的画面,把程序写到Layer里面
			var xmlb = "";
			var ZiDian1 = {}; //用于支架弹窗
			var ZiDian2 = {};
			var ZiDian3 = {};
			var data2 = {};
			var HH = []; //HH作为全局传递Hdata的数组
			var DD = []; //DD作为全局传递Ddata的数组
			var JYJG = ""; //检验结果,全局变量,用于发后台存储
			var ycidd = []; //存异常ID的key值列表,然后用来find
			//这里开始写jexcle
			var DuXie = [{
				type: 'text',
				readOnly: true
			}, {
				type: 'text',
				readOnly: true
			}, {
				type: 'number',
				wordWrap: true
			}];
			var LieMing = [
				'检验代码', '检验项目', '不良数量(K)'
			];
			var LieKuan = [
				80, 150, 100
			];
			//这里开始写入机台对应的站别
			var JT = {
				"BPA": "固晶",
				"BPC": "焊线",
				"BPD": "点胶",
				"BPG": "切割",
				"BPI": "分光",
				"BPJ": "编带"
			}

			//这里开始写入机台故障号码
			var YC = {
				"EXC02": "生产调机",
				"EXC03": "更换耗材",
				"EXC04": "日点检保养",
				"EXC05": "冶具清理",
				"EXC06": "工单切换调机",
				"EXC11": "设备故障调机",
				"EXC21": "其他计划外停机",
				"EXC22": "待机",
				"EXC31": "生产调机首检",
				"EXC32": "换单首检",
				"EXC33": "换耗材首检"
			}

			//这里开始写入s2的对照表
			var STR2 = {
				"EM": "YGGH"
				//,"AT":"DQGD"
				//,"BP":"DQJT"
			}

			var wsjson = {} //WebSocket传回来的json
			var msgcnt = 0;

			var Str2 = "0"; //取前面两个字符进行下面的判断
			var JT2 = {}; //机台的字典: 存扫描的次数 i
			var DQYC = {}; //存机台当前的异常, 如果异常不是当前异常就发出警告
			var i = 0;
			var YCT = {};
			var JTGD = {}; //这里是机台号对应工单号的数组

			//载入layui模块：layer弹出层,form表单,element元素组件做分页或其他
			layui.use(['jquery', 'layer', 'form', 'element'], function() {
				var $ = layui.$; //重点处
				var layer = layui.layer;
				var form = layui.form;
				var element = layui.element;
				var table = layui.table;

				form.on('checkbox(jpfx)', function(data) {
					if(data.elem.checked) {
						jpfx = 1;
					} else {
						jpfx = 0;
					}
				});

				form.on('checkbox(zjfx)', function(data) {
					if(data.elem.checked) {
						zjfx = 1;
					} else {
						zjfx = 0;
					}
				});

				//这里是画面准备完毕后执行的程式
				$(document).ready(function() {
					//如果HTML5WEB存储存在,就查询,否则就弹窗提示
					if(localStorage.scyggh) {
						$("#YGGH").val(localStorage.scyggh);
						$.ajax({
							type: 'POST',
							url: "http://172.31.3.27:84/index.php?s=/scancode/Product/xm", //172.31.3.27:84//127.0.0.1:85,//POST傳一個超長字串到後端
							data: "qrc=" + localStorage.scyggh,
							dataType: "json",
							success: function(sss) {
								//layer.msg('工单号：' + getGongDanHao[0] + '报工完成。');
								if(sss.msg) {
									layer.msg(sss.msg);
								}

								layer.msg(sss['XM'] + ',欢迎回来!');
								$("#YGXM").val(sss['XM']); //把姓名单独查出来
							}
						});
						yc(); //调用写异常的方法
					} else {
						layer.msg("请扫工号牌");
					}

					//监听指定单选框
					form.on('radio(jyjg)', function(data) {
						JYJG = data.value;
					});

					$("#qr").select(); //画面准备完毕后就选择扫码输入框

					if(localStorage.scgongxu) //如果gongxu的h5存储存在,就
					{
						lianjie(localStorage.scgongxu); //调用连接方法
					}
				});

				$('#mytable').jexcel({
					allowDeleteColumn: false, //不允许删除行
					rowDrag: false, //不允许拖动
					allowManualInsertRow: false, //禁止用户插入一个新列(只能存在1笔)
					allowManualInsertColumn: false, //不允许新增列
					columnSorting: false, //不允许排序
					columns: DuXie,
					colHeaders: LieMing,
					colWidths: LieKuan
				});

				//这里是扫描输入框的回车按下后执行的程式
				$("#qr").keypress(function(e) {
					//如果按下的键值是回车键13就执行以下语句
					if(e.keyCode === 13) {
						//扫描输入框选择
						$("#qr").select();
						//定义局部变量QRC=扫描输入框的值
						var QRC = $("#qr").val();
						//取前面两个字符进行下面的判断
						var s2 = QRC.substr(0, 2);
						var s3 = QRC.substr(0, 3);
						/*
						TAAK17B2681-2 T2865811K-Q4801A 10 002
						编带站的正则测试
						11 11.7 2.7 2.8 C22 U0C22Y1 80 90 65 BPI31798706019-1 AK187029C-X T2850812K-Q31B3A 8
						http://tool.oschina.net/regex测试通过
						*/
						var patt1 = /^[A-Z]{1,2}[A-Z\d]*\-?[A-Z\d]?(?= T)/; //AK17B2681-2 -> mg组装规格书工单号
						var patt2 = /\d{3}$/; //002组装规格书盒序号
						var patt3 = /[A-Z]{1,2}[A-Z\d]{4,7}\-?[A-Z\d]?(?= T)/; //AK187029C-X分光标签工单号
						var patt4 = /BP[A-Z][A-Z\d]*\-?[A-Z\d]*(?= [A-Z]{1,2})/; //BPI31798706019-1分光标签序号(用作唯一码)
						var patt5 = /BP[A-Z]\d{4}/; //机台号或MES机台EQ
						var patt6 = /\d+(?= \d{3}$)/; //组装规格书基准片数
						var patt7 = /^TA/; //兼容,还是要替换掉TA

						if(QRC == "EXC04") {
							$("#GDH").val("点检工单默认为空");
						} else if(QRC == "EXC22") {
							$("#GDH").val("待机工单默认为空");
						}

						if(/^\d{1,2}$/.test(QRC) && $("#DQJT").val() != "" && $("#GDH").val() != "") {
							var sqty = QRC * 1;
							if(sqty <= 20) { //片数小于或等于20片 -> mg
								$.ajax({
									type: 'POST',
									url: "http://172.31.3.27:84/index.php?s=/scancode/Product/bgupd", //172.31.3.27:84//127.0.0.1:85,//POST傳一個超長字串到後端
									data: "hdjson=" + JSON.stringify({
										'getJiTai': $("#DQJT").val(),
										'getQTY': sqty,
										'getYGGH': $("#YGGH").val(),
										'GDH': $("#GDH").val()
									}),
									dataType: "json",
									success: function(sss) {
										//layer.msg('工单号：' + getGongDanHao[0] + '报工完成。');
										if(sss.msg) {
											layer.msg(sss.msg);
										}
									}
								});
							} else {
								layer.msg("请确认当前料盒的装片上限!");
								return;
							}
							return;
						}

						//取出工单号
						var string1 = QRC.replace(patt7, "");
						if(patt1.test(string1) || patt3.test(string1)) {
							if(patt1.test(string1)) { //组装规格书工单号测试通过
								GD = patt1.exec(string1) + "";
								//prqrf(); //调用pr确认的function
								var string2 = patt1.exec(string1) + "-" + patt2.exec(string1);
								$("#GDH").val(string2);
								JTGD[$("#DQJT").val()] = string2;

								if($("#DQJT").val() != "") {
									var getGongDanHao = patt1.exec(string1);
									var getQTY = patt6.exec(string1);
									var getHH = patt2.exec(string1);
									var dqycid = $("#" + $("#DQJT").val() + "d").data("ycid");
									//
									$.ajax({
										type: 'POST',
										url: "http://172.31.3.27:84/index.php?s=/scancode/Product/bgkeep", //172.31.3.27:84//127.0.0.1:85,//POST傳一個超長字串到後端
										data: "hdjson=" + JSON.stringify({
											'getJiTai': $("#DQJT").val(),
											'getGongDanHao': getGongDanHao[0],
											'getQTY': getQTY[0],
											'getYGGH': $("#YGGH").val(),
											'getHeHao': getHH[0],
											'QR': QRC,
											'GDH': string2
										}),
										dataType: "json",
										success: function(sss) {

											//layer.msg('工单号：' + getGongDanHao[0] + '报工完成。');
											if(sss.msg) {
												layer.msg(sss.msg);
											}

											if(sss.pr) {
												prf = false;
											} else {
												prf = true;
											}

											if(sss.STIME) {
												if($("#" + $("#DQJT").val() + "d").html() == undefined) { //当机台号没有的时候就添加,否则就在下面新增履历
													$("#YC").prepend(
														"<div id='" + $("#DQJT").val() + "d' class='layui-col-xs6 layui-col-sm4 layui-col-md2 layui-anim-up  layui-bg-blue' data-jt='" + $("#DQJT").val() + "' data-gdh='" + string2 + "' onclick='showDetails(this)'>" +
														"	<fieldset id='" + $("#DQJT").val() + "' class='layui-elem-field layui-form layui-form-pane'>" +
														"		<legend>机台号: " + $("#DQJT").val() + "</legend>" +
														"		<div class='layui-field-box'>" +
														"			<div>" +
														"				<br/>报工工单: " + string2 +
														"				<br/>报工时间: " + sss.STIME +
														"			</div>" +
														"		</div>" +
														"	</fieldset>" +
														"</div>"
													);
												} else {
													$("#" + $("#DQJT").val() + " div.layui-field-box:first").prepend(
														"<div>" +
														"	<br/>报工工单: " + string2 +
														"	<br/>报工时间: " + sss.STIME +
														"</div>"
													);

													$("#" + $("#DQJT").val() + "d").data("gdh", string2); //增加报工的工单号到data-
													$("#" + $("#DQJT").val() + "d").data("ycid", dqycid);
													$("#" + $("#DQJT").val() + "d").prependTo("#YC"); //扫到这里的时候,就把它放到异常框的最前面
												}
											}
										}
									});
								}

							} else if(patt3.test(QRC)) {
								var string2 = patt3.exec(QRC) + "-" + patt4.exec(QRC);
								$("#GDH").val(string2);
								JTGD[$("#DQJT").val()] = string2;
							} else {
								layer.msg('工单号的正则不通过，请检查！<br/>组装规格书是否是TA开头？<br/>编带站卷盘标签是否包含工单号');
							}
						} else if(patt5.test(QRC)) { //取到工单号就不会跑来取机台号了吧,编带机上面的流水码是BPI分光机自动标签s2==="BP" && $("#GDH").val() !=="")
							var dqjt = patt5.exec(QRC);
							var string3 = "";
							string3 = dqjt[0].substr(0, 3);
							ycjt(dqjt); //准备改代码
							
							getabnormal(dqjt[0]);
							
							
							if(string3 == "BPG") {
								//新增弹窗
								zjf();
							}
							$("#DQJT").val(dqjt[0]);
							JTGD[dqjt[0]] = $("#GDH").val(); //当前机台的工单号

							if(string3 != localStorage.scgongxu) {
								localStorage.scgongxu = string3;
								lianjie(string3);
							}

						} else if(STR2[s2]) {
							$("#" + STR2[s2]).val(QRC);
							//判断如果是工号就写WEB存储
							if(s2 === "EM") {
								$("#YC").html("");
								localStorage.scyggh = QRC;
								location.reload(); //如果是工号,还要清除字典内容,重新来过...所以干脆刷新一下好了,下面是语句
							}
						} else if(/^EXC\d{2}$/.test(QRC) && $("#DQJT").val() !== "" && $("#YGGH").val() !== "" && $("#GDH").val() !== "") {
							$.ajax({
								type: 'POST',
								url: "http://172.31.3.27:84/index.php?s=/scancode/Product/ycins", //172.31.3.27:84//127.0.0.1:85,//POST傳一個超長字串到後端
								data: "hdjson=" + JSON.stringify({
									'getJiTai': $("#DQJT").val(),
									'getYGGH': $("#YGGH").val(),
									'GDH': $("#GDH").val(),
									'YiChangMa': QRC,
								}),
								dataType: "json",
								success: function(sss) {
									//layer.msg('工单号：' + getGongDanHao[0] + '报工完成。');
									if(sss.msg) {
										layer.msg(sss.msg);
									}

									if(sss.STIME) {
										if($("#" + $("#DQJT").val() + "d").html() == undefined) { //当机台号没有的时候就添加,否则就在下面新增履历
											$("#YC").prepend(
												"<div id='" + $("#DQJT").val() + "d' class='layui-col-xs6 layui-col-sm4 layui-col-md2 layui-anim-up  layui-bg-blue' data-jt='" + $("#DQJT").val() + "' onclick='showDetails(this)'>" +
												"	<fieldset id='" + $("#DQJT").val() + "' class='layui-elem-field layui-form layui-form-pane'>" +
												"		<legend>机台号: " + $("#DQJT").val() + "</legend>" +
												"		<div class='layui-field-box'>" +
												"			<div>" +
												"				<br/>机台状态: " + YC[QRC] +
												"				<br/>开始时间: " + sss.STIME +
												"			</div>" +
												"		</div>" +
												"	</fieldset>" +
												"</div>"
											);
										} else {
											$("#" + $("#DQJT").val() + " div.layui-field-box:first").prepend(
												"<div>" +
												"	<br/>机台状态: " + YC[QRC] +
												"	<br/>开始时间: " + sss.STIME +
												"</div>"
											);
											$("#" + $("#DQJT").val() + "d").prependTo("#YC"); //扫到这里的时候,就把它放到异常框的最前面
										}
										$("#" + $("#DQJT").val() + "d").data('ycid', sss.YCID);
										$("#" + $("#DQJT").val() + "d").data('gdh', $("#GDH").val());
									}
								}
							});
						} else {
							layer.msg('员工工号、当前机台和工单号不允许为空');
						}
					}
				});
				//当程序的二维码输入框失去焦点后的事件,重新返回焦点
				$("#qr").blur(function() {
					//layer.msg('无法点击除输入框外的地方,将自动选择输入框<br/><small><small>ps:此提示会自动消失</small></small>');
					if($("#ZJ").attr("class") == "layui-tab-item layui-show") {
						return;
					} else {
						$("#qr").select();
					}
				});

				//if(s3 !== localStorage.scgongxu){//如果s3不等于gongxu,那么就重新连接
				//连接程序,写一次,被其他调用,而只需要改这里即可

				$("#keep").click(function() {
					HH = [];
					DD = [];

					var Ddata = $('#mytable').jexcel('getData');

					if((Ddata[0][0] == "" || Ddata[0][1] == "") && JYJG == 'NG') {
						layer.tips("<span style='color:red'><big><b>未保存，NG时，请确认是否已选择自检项目。</b></big></span>", this, {
							tips: [2, '#fff']
						});
					} else if($("#DQJT").val() == "" || $("#GDH").val() == "") {
						layer.tips("<span style='color:red'><big><b>未保存！请确认【机台号】或【工单号】是否有输入。</b></big></span>", this, {
							tips: [2, '#fff']
						});
					} else if(JYJG) {
						if(JYJG == 'NG' && Ddata[0][2] == '' && Ddata.length < 1) {
							layer.tips("<span style='color:red'><big><b>未保存！NG时，请确认【不良数量】是否有输入。</b></big></span>", this, {
								tips: [2, '#fff']
							});
						} 
//						else if(JYJG == 'OK' && Ddata[0][0] != '') {
//							layer.tips("<span style='color:red'><big><b>未保存！OK时，请不要点检验项目，或请切换/刷新单据，重新记录。</b></big></span>", this, {
//								tips: [2, '#fff']
//							});
//						} 
						else {
							HH.push({
								'YGGH': localStorage.scyggh,
								'DQJT': $("#DQJT").val(),
								'DQGDH': $("#GDH").val(),
								'JG': JYJG,
								'BZ': $("#BZSTR").val()
							});

							for(var k in Ddata) {
								DD.push({
									"BLXMID": Ddata[k][0],
									"BLQTY": Ddata[k][2]
								});
							}

							$.ajax({
								type: 'POST',
								url: "http://172.31.3.27:84/index.php?s=/scancode/Product/zjkeep", //172.31.3.27:84//127.0.0.1:85
								data: "hdjson=" + JSON.stringify({
									'HH': HH,
									'DD': DD
								}),

								dataType: "json",
								success: function(sss) {
									console.log(sss);
									if(sss['msg']) {
										layer.msg(sss['msg']);
										if(sss['msg'] == '保存成功') {
											$('#mytable').jexcel('setData', [
												[]
											]);
											$('#BZSTR').val("");
										}
									}
								}
							});
						}
					} else {
						layer.tips("<span style='color:red'><big><b>未保存！请检查【判定结果】是否有选择，【不良数量】是否有填写！</b></big></span>", this, {
							tips: [2, '#fff']
						});
					}
				});
			}); //layui尾巴

			function ycjt(data) {
				$("#GDH").val("");
				$.ajax({
					type: 'POST',
					url: "http://172.31.3.27:84/index.php?s=/scancode/product/ycjt", //POST傳一個超長字串到後端
					data: "DQJT=" + data,
					dataType: "JSON",
					success: function(sss) {
						for(var x in sss.YC) {
							if($("#" + sss.YC[x]['YiChangJiTai'] + "d").data("ycid") == x) {
								layer.msg("已经存在相同YCID了，YCID：" + x);
								$("#" + sss.YC[x]['YiChangJiTai'] + "d").prependTo("#YC"); //扫到这里的时候,就把它放到异常框的最前面
							} else {
								var clstr = "";
								if(sss.YC[x]['JG'] == 'OK' || sss.YC[x]['FJG'] == 'OK') {
									clstr = "class='layui-col-xs6 layui-col-sm4 layui-col-md2 layui-anim-up layui-bg-orange'";
								} else if(sss.YC[x]['JG'] == 'NG' || sss.YC[x]['FJG'] == 'NG') {
									clstr = "class='layui-col-xs6 layui-col-sm4 layui-col-md2 layui-anim-up layui-bg-red'";
								} else {
									clstr = "class='layui-col-xs6 layui-col-sm4 layui-col-md2 layui-anim-up layui-bg-blue'";
								}

								$("#YC").prepend(
									"<div id='" + sss.YC[x]['YiChangJiTai'] + "d' " + clstr + " data-jt='" + sss.YC[x]['YiChangJiTai'] + "' data-ycid='" + sss.YC[x]['YCID'] + "' data-gdh='" + sss.YC[x]['GongDanHao'] + "' onclick='showDetails(this)'>" +
									"	<fieldset id='" + sss.YC[x]['YiChangJiTai'] + "' class='layui-elem-field layui-form layui-form-pane'>" +
									"		<legend>机台号: " + sss.YC[x]['YiChangJiTai'] + "</legend>" +
									"		<div class='layui-field-box'>" +
									"			<div>" +
									"				<br/>机台状态: " + YC[sss.YC[x]['YiChangMa']] +
									"				<br/>开始时间: " + sss.YC[x]['YiChangStartTime'] +
									"			</div>" +
									"		</div>" +
									"	</fieldset>" +
									"</div>"
								);
							}
						}
					}
				});
			}

			function yc() {
				$.ajax({
					type: 'POST',
					url: "http://172.31.3.27:84/index.php?s=/scancode/product/yc", //POST傳一個超長字串到後端
					data: "qrc=" + localStorage.scyggh,
					dataType: "JSON",
					success: function(sss) {
						for(var x in sss.YC) {
							var clstr = "";
							if(sss.YC[x]['JG'] == 'OK' || sss.YC[x]['FJG'] == 'OK') {
								clstr = "class='layui-col-xs6 layui-col-sm4 layui-col-md2 layui-anim-up layui-bg-orange'";
							} else if(sss.YC[x]['JG'] == 'NG' || sss.YC[x]['FJG'] == 'NG') {
								clstr = "class='layui-col-xs6 layui-col-sm4 layui-col-md2 layui-anim-up layui-bg-red'";
							} else {
								clstr = "class='layui-col-xs6 layui-col-sm4 layui-col-md2 layui-anim-up layui-bg-blue'";
							}

							$("#YC").append(
								"<div id='" + sss.YC[x]['YiChangJiTai'] + "d' " + clstr + " data-jt='" + sss.YC[x]['YiChangJiTai'] + "' data-ycid='" + sss.YC[x]['YCID'] + "' data-gdh='" + sss.YC[x]['GongDanHao'] + "' onclick='showDetails(this)'>" +
								"	<fieldset id='" + sss.YC[x]['YiChangJiTai'] + "' class='layui-elem-field layui-form layui-form-pane'>" +
								"		<legend>机台号: " + sss.YC[x]['YiChangJiTai'] + "</legend>" +
								"		<div class='layui-field-box'>" +
								"			<div>" +
								"				<br/>机台状态: " + YC[sss.YC[x]['YiChangMa']] +
								"				<br/>开始时间: " + sss.YC[x]['YiChangStartTime'] +
								"			</div>" +
								"		</div>" +
								"	</fieldset>" +
								"</div>"
							);
						}
					}
				});
			}

			function showDetails(data) {
				var jtdata = data.getAttribute("data-jt");
				var iddata = data.getAttribute("data-ycid");
				var gddata = data.getAttribute("data-gdh");

				var kaichuang = layer.open({
					type: 1,
					content: '是否要结束该状态',
					btn: ['关闭', '自检', '确定结束'],
					yes: function() {
						layer.close(kaichuang);
						layer.msg("取消被按下了");
						return false;
					},
					btn2: function() {
						layui.use(['element'], function() {
							var element = layui.element;
							element.tabChange('demo', 'zjid'); //切换
						});

						$("#DQJT").val(jtdata);
						$("#GDH").val(gddata);
						zijian(this);
					},
					btn3: function() {
						layer.msg("确定被按下了,按下的机台是" + jtdata);

						$.ajax({
							type: 'POST',
							url: "http://172.31.3.27:84/index.php?s=/scancode/Product/ycupd", //172.31.3.27:84//127.0.0.1:85,//POST傳一個超長字串到後端
							data: "YCID=" + iddata + "&YGGH=" + localStorage.scyggh,
							dataType: "json",
							success: function(sss) {
								//layer.msg('工单号：' + getGongDanHao[0] + '报工完成。');
								if(sss.msg) {
									layer.msg(sss.msg);
								}

								if(sss.ETIME) { //异常结束时间
									$("#" + jtdata + " div.layui-field-box div:first").append("<br/>结束时间: " + sss.ETIME);
									$("#" + jtdata + "d").attr("class", "layui-col-xs6 layui-col-sm4 layui-col-md2 layui-anim-up  layui-bg-green");
								}

								layer.close(kaichuang);
							}
						});
					}
				});
			}

			function lianjie(data) {
				var uid = data;

				$("#uid").html(uid);
				var socket = io('http://' + document.domain + ':2120'); // 连接服务端

				socket.on('connect', function() // 连接后登录
					{
						socket.emit('login', uid);
					});

				socket.on('new_msg', function(msg) // 后端推送来消息时
					{
						//保留最近的30条信息,收到通讯消息时处理function
						console.log(msg.replace(/&quot;/g, '"')); //jsonStr.replace('&quot','"')
						wsjson = $.parseJSON(msg.replace(/&quot;/g, '"'));
						if(wsjson.msg) {
							msgcnt += 1;
							if(msgcnt >= 5) {
								var msgstr = wsjson.msg + "\n" + $("#information").val();
								$("#information").val(msgstr.replace(/\n.*?$/, ""));
							} else {
								$("#information").val(wsjson.msg + "\n" + $("#information").val());
							}
						}

						if(wsjson.sss.JG == "OK") {
							$("#" + wsjson.sss.JT + "d").attr("class", "layui-col-xs6 layui-col-sm4 layui-col-md2 layui-anim-up  layui-bg-orange");
						} else if(wsjson.sss.JG == "NG") {
							$("#" + wsjson.sss.JT + "d").attr("class", "layui-col-xs6 layui-col-sm4 layui-col-md2 layui-anim-up  layui-bg-red");
						}
					});

				socket.on('update_online_count', function(online_stat) // 后端推送来在线数据时
					{
						$('#online_box').html(online_stat);
					});
			}

			function zijian(data) {
				$("#YCQ").html("");
				ZiDian2 = {}
				Dhtml = "";

				$.ajax({
					url: "http://172.31.3.27:84/index.php?s=/scancode/Product/zijian", //172.31.3.27:84//127.0.0.1:85
					data: "GX=" + localStorage.scgongxu,
					dataType: "JSON",
					success: function(sss) {
						if(sss['msg']) {
							layer.msg(sss['msg']);
						}

						ycidd = [];

						for(k = 0; k < sss.JY.length; k++) {
							var d = sss['JY'][k]['JYXMDM'];
							var xmdm = d;
							var jyxm = sss['JY'][k]['JYMXSM'];

							ZiDian3[d] = [xmdm, jyxm];

							ycidd.push(d);

							if(ZiDian2[d]) {
								ZiDian2[d] = '代码：' + xmdm + '丨说明：' + jyxm;
								$("#" + d).html(ZiDian2[d]);
								$("#" + d).data("d", d); //更改数据d的内容
							} else {
								ZiDian2[d] = '代码：' + xmdm + '丨说明：' + jyxm;
								html = "<button id='" + d + "' class='layui-btn layui-col-xs12 layui-col-sm5 layui-col-md4 layui-btn-normal' data-d='" + d + "' onclick='showJY(this)'>" + ZiDian2[d] + "</button>";
								$("#YCQ").append(html);
							}
						}

						var data1 = [
							[ZiDian2[d], , '0.00%']
						];
						$('#mytable').jexcel('setData', data1);
						data2 = {};
						$('#mytable').jexcel('setData', [
							[]
						]);
					}
				});
			}

			function showJY(data) {
				var d1 = data.getAttribute("data-d");
				data.disabled = true; //开始时间按钮被禁用
				data.className = 'layui-btn layui-btn-xs layui-btn-normal layui-btn-disabled'; //添加禁用渲染

				console.log(data);

				data2[d1] = [d1, ZiDian3[d1][0], ZiDian3[d1][1]];
				var result = Object.keys(data2).map(function(key) {
					return [data2[key][1], data2[key][2], data2[key][3]];
				});
				//console.log(result);
				$('#mytable').jexcel('setData', result);
				JT = "";
			}

			function prqrf() {
				var s3 = $("#DQJT").val().substr(0, 3);
				if(prf && s3 == "BPA") {
					var prqr = layer.open({
						title: 'PR确认',
						type: 1,
						offset: 'auto',
						content: "<div class='layui-form'>" +
							"	<div class='layui-form-item'>" +
							"		<label class='layui-form-label'>复选框</label>" +
							"		<div class='layui-input-block'>" +
							"			<input lay-filter='jpfx' type='checkbox' title='晶片反向'/>" +
							"			<input lay-filter='zjfx' type='checkbox' title='支架反向'/>" +
							"		</div>" +
							"	</div>" +
							"</div>", //内容
						btn: ['保存', '关闭'],
						yes: function() {
							if($("#DQJT").val() != "" && $("#GDH").val() != "") {
								$.ajax({
									type: 'POST',
									url: "http://172.31.3.27:84/index.php?s=/scancode/Product/prqr", //172.31.3.27:84//127.0.0.1:85
									data: "YGGH=" + localStorage.scyggh +
										"&DQJT=" + $("#DQJT").val() +
										"&GDH=" + GD +
										"&JPFX=" + jpfx +
										"&ZJFX=" + zjfx,
									dataType: "json",
									success: function(sss) {
										//layer.msg('工单号：' + getGongDanHao[0] + '报工完成。');
										if(sss.msg) {
											layer.msg(sss.msg);
										}

										if(sss.ETIME) { //PR确认时间
											$("#" + jtdata + " div.layui-field-box div:first").prepend("PR确认时间: " + sss.ETIME + "<br/>");
										}
									}
								});

								layer.close(prqr);
							} else {
								layer.msg("机台号或工单号不能为空"); //这里不会有机会跑到吧?
							}
						},
						btn2: function() {
							layer.close(prqr);
							layer.msg("取消被按下了");
							return false;
						}
					});
					layui.use(['form'], function() {
						var form = layui.form;
						form.render(); //form渲染
					});
				} else if(s3 == "BPA") {
					layer.msg("已经做过PR确认"); //这里不会有机会跑到吧?
				}

			}

			Date.prototype.format = function(fmt) { //这里是日期格式化公式
				var o = {
					"M+": this.getMonth() + 1, //月份
					"d+": this.getDate(), //日
					"h+": this.getHours(), //小时
					"m+": this.getMinutes(), //分
					"s+": this.getSeconds(), //秒
					"q+": Math.floor((this.getMonth() + 3) / 3), //季度
					"S": this.getMilliseconds() //毫秒
				}

				if(/(y+)/.test(fmt)) {
					fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				}

				for(var k in o) {
					if(new RegExp("(" + k + ")").test(fmt)) {
						fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
					}
				}

				return fmt;
			}

			function zjf() {
				ZiDian1 = {};
				Dhtml = "";
				$.ajax({
					type: 'POST',
					url: "http://172.31.3.27:84/index.php?s=/scancode/Product/zjf", //172.31.3.27:84//127.0.0.1:85
					dataType: "json",
					success: function(sss) {
						for(var k in sss['DTZJ']) {
							var d = sss['DTZJ'][k]['id'];
							var zjxh = sss['DTZJ'][k]['ZhiJiaXingHao'];
							var zjdx = sss['DTZJ'][k]['ZhiJiaDaXiao'];
							var dpqty = sss['DTZJ'][k]['DaPianQTY'];

							ZiDian1[d] = zjxh + '-' + zjdx + '-' + dpqty;

							Dhtml += "" +
								"<tr id='" + d + "'>" +
								"<td>" + "<button id='" + d + "' class='layui-btn layui-btn-sm layui-btn-normal' data-d='" + d + "' onclick='showZJ(this)'>" + d + "</button></td>" +
								"<td>" + zjxh + "</td>" +
								"<td>" + zjdx + "</td>" +
								"<td>" + dpqty + "</td>" +
								"</tr>";
						}
						Hhtml = "" +
							"<table lay-even class='layui-table' lay-size='sm'>" +
							"<thead>" +
							"<th lay-data='{field:'d', width:100}' >序号</th>" +
							"<th lay-data='{field:'zjxh', width:100}' >支架型号</th>" +
							"<th lay-data='{field:'zjdx', width:100}' >支架大小</th>" +
							"<th lay-data='{field:'dpqty', width:100}' >1小片（K）</th>" +
							"</thead>" +
							"<tbody>";

						zjler = layer.open({
							title: '支架',
							type: 1,
							offset: 'auto',
							content: Hhtml + Dhtml + "</tbody></table>",
						});
					}
				});
			}

			function showZJ(data) {
				var d1 = data.getAttribute("data-d");
				//console.log(d1);
				data.disabled = true; //开始时间按钮被禁用
				data.className = 'layui-btn layui-btn-xs layui-btn-normal layui-btn-disabled'; //添加禁用渲染
				//layer.msg("Layer的按钮被点击!");
				data2[d1] = [d1, ZiDian1[d1][0], ZiDian1[d1][1], ZiDian1[d1][6]];
				var result = Object.keys(data2).map(function(key) {
					return [data2[key][0], data2[key][1], data2[key][2], data2[key][3]];
				});
				$('#GDH').val(ZiDian1[d1]);
				layer.close(zjler);
				
			}
			function getabnormal(JiTai){
				$("#abnormal").html("");
				//YCCODE=QRC+';'+YCCODE;
				$.ajax({
					type:'POST',
					async: false,
					url: "http://172.31.3.27:84/index.php?s=/scancode/Product/abnormalinformation",//POST傳一個超長字串到後端
					data:"JiTai="+JiTai,
					dataType : "JSON",
					success:function(sss){
						//$("#YCXX").val(sss[0]["异常现象"]+';'+$("#YCXX").val());
						//console.log(sss);
						for(var k in sss['abnormal'])
						{
							var EXC=sss['abnormal'][k]["EXC"];
							var YiChang = sss['abnormal'][k]['YiChang'];
							//console.log(k);
							//console.log(YiChang);
							$("#abnormal").prepend(
									"<div class='layui-col-sm2'>"+ 
										"<button id='"+'button'+k+"' value='"+'value'+k+"' class='layui-btn layui-btn-fluid layui-btn-radius'  onclick='showabnormal(this) 'return on_del_click("+'value'+k+",this)' data-delid-qty='"+EXC+"'>"+YiChang+
										"</button>"+	
									"</div>"
								);
						}
						//$("#YCXX").val($("#YCXX").val()+ycxx+';');
						//$("#YCXX").val(ycxx+';'+$("#YCXX").val());
					}
				});
			}
			function showabnormal(del_id)
			{//自动识别button组
				EXCinformation=$(del_id).html();//获取button的按键值
				
				EXC = del_id.getAttribute("data-delid-qty");//按键对应的处理代码
				$("#del_id").hide();
				
				buttonid=del_id.getAttribute("id");
				//console.log(EXC+"-"+EXCinformation+"-"+buttonid);
				//$("#"+buttonid).remove();
				//console.log($("#DQJT").val()+"-"+$("#YGXM").val()+"-"+$("#startime").val()+"-"+$("#endtime").val()+"-"+$("#YCXX").val()+"-"+EXCinformation+"-"+YCCODE+"-"+EXC);
				
				if($("#DQJT").val() !== "" && $("#YGGH").val() !== "" && $("#GDH").val() !== "") 
				{
					ycinst(EXC,EXCinformation);
					$("#abnormal").html("");
				}
				else{
					layer.msg('员工工号、当前机台和工单号不允许为空');
				}
				/*$("#DQJT").val("");
				$("endtime").val("");*/
				//location.reload();
			}
			function ycinst(EXC,EXCinformation){
				$.ajax({
					type: 'POST',
					url: "http://172.31.3.27:84/index.php?s=/scancode/Product/ycins", //172.31.3.27:84//127.0.0.1:85,//POST傳一個超長字串到後端
					data: "hdjson=" + JSON.stringify({
						'getJiTai': $("#DQJT").val(),
						'getYGGH': $("#YGGH").val(),
						'GDH': $("#GDH").val(),
						'YiChangMa': EXC,
					}),
					dataType: "json",
					success: function(sss) {
						//layer.msg('工单号：' + getGongDanHao[0] + '报工完成。');
						if(sss.msg) {
							layer.msg(sss.msg);
						}

						if(sss.STIME) {
							if($("#" + $("#DQJT").val() + "d").html() == undefined) { //当机台号没有的时候就添加,否则就在下面新增履历
								$("#YC").prepend(
									"<div id='" + $("#DQJT").val() + "d' class='layui-col-xs6 layui-col-sm4 layui-col-md2 layui-anim-up  layui-bg-blue' data-jt='" + $("#DQJT").val() + "' onclick='showDetails(this)'>" +
									"	<fieldset id='" + $("#DQJT").val() + "' class='layui-elem-field layui-form layui-form-pane'>" +
									"		<legend>机台号: " + $("#DQJT").val() + "</legend>" +
									"		<div class='layui-field-box'>" +
									"			<div>" +
									"				<br/>机台状态: " + EXCinformation +
									"				<br/>开始时间: " + sss.STIME +
									"			</div>" +
									"		</div>" +
									"	</fieldset>" +
									"</div>"
								);
							} else {
								$("#" + $("#DQJT").val() + " div.layui-field-box:first").prepend(
									"<div>" +
									"	<br/>机台状态: " + EXCinformation +
									"	<br/>开始时间: " + sss.STIME +
									"</div>"
								);
								$("#" + $("#DQJT").val() + "d").prependTo("#YC"); //扫到这里的时候,就把它放到异常框的最前面
							}
							$("#" + $("#DQJT").val() + "d").data('ycid', sss.YCID);
							$("#" + $("#DQJT").val() + "d").data('gdh', $("#GDH").val());
						}
					}
				});
			}
		</script>
	</body>

</html>